﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SharpCommon.ORM.Common
{
    public class ReflectionUtils
    {
        public static PropertyInfo[] GetProperties(Type type)
        {
            return type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
        }
        public static FieldInfo[] GetFields(Type type)
        {
            return type.GetFields(BindingFlags.Public | BindingFlags.Instance);
        }
        public static void SetPropertyValue(object obj, PropertyInfo property, object value)
        {
            SetHandler setter = DynamicMethodCompiler.CreateSetHandler(obj.GetType(), property);
            Type type = property.PropertyType;
            value = TypeUtils.ConvertForType(value, type);
            setter(obj, value);
        }
        public static object GetPropertyValue(object obj, PropertyInfo property)
        {
            GetHandler getter =DynamicMethodCompiler.CreateGetHandler(obj.GetType(), property);
            return getter(obj);
        }
    }
}
